package org.budo.netty.servlet.server.handler.servlet.dispatcher;

import java.io.IOException;

import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

import org.budo.netty.servlet.server.handler.servlet.BudoServletRequest;
import org.budo.netty.servlet.util.RequestUtil;

/**
 * @author lmw
 */
public class BudoNameRequestDispatcher implements RequestDispatcher {
    private String name;

    public BudoNameRequestDispatcher(String name) {
        this.name = name;
    }

    @Override
    public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        BudoServletRequest budoServletRequest = RequestUtil.getBudoServletRequest(request);

        BudoNameRequestDispatcherRequest dispatcherRequest = new BudoNameRequestDispatcherRequest(this.name, budoServletRequest);
        budoServletRequest.getBudoServletHandler().handleRequest(dispatcherRequest, (HttpServletResponse) response, DispatcherType.FORWARD);
    }

    @Override
    public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        throw new UnsupportedOperationException();
    }
}
